const dayjs = require('@/utils/dayjs.js')

const dateFormat = (str, fmt = 'YYYY-MM-DD HH:mm:ss') => {
  return dayjs(str).format(fmt)
}

//计算剩余时间  86400000  3600000
const dayDiff = (str) => {
  let tmp = ''
  const date = new Date(str).getTime() + 86400000
  const now = new Date().getTime()
  if (date < now) {
    return '已过期'
  }
  const days = parseInt((date - now) / 86400000)
  const hours = parseInt((date - now - days * 86400000) / 3600000)
  if (days === 0 && hours === 0) {
    tmp = '不足1小时'
  } else {
    if (days !== 0) {
      tmp = days + '天'
    }
    if (hours !== 0) {
      tmp = tmp + hours + '小时'
    }
  }
  return tmp
}
export { dateFormat, dayDiff }
